import BaseUtil from '@/BaseUtil';
import BuffUtil from '@/BuffUtil';
import RandomUtil from '@/RandomUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/* 惩戒之锤 */
export default class QS_SmiteHarmmor extends AbilityBase {
    static instance: QS_SmiteHarmmor;
    buffType: AppBuffType = {
        id: 'buff_QS_SmiteHarmmor',
        art: this.art,
        name: this.abilityName,
        ubertip: '该单位造成伤害的能力下降了',
        dur: 2,
        attribute: {
            物理伤害倍率: -0.25,
            法术伤害倍率: -0.25,
        },
    };
    constructor(id: string) {
        super(id);
        QS_SmiteHarmmor.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let x = GetUnitX(target);
        let y = GetUnitY(target);
        let ef = CreateUnit(GetOwningPlayer(source), 'vcjc', x, y, RandomUtil.randomAngle());
        SetUnitFlyHeight(ef, 90, 1200);
        BaseUtil.runLater(0.6, () => {
            this.intervalEffect(source, x, y);
            BaseUtil.onTimer(1, (c) => {
                this.intervalEffect(source, x, y);
                if (c >= 6) {
                    KillUnit(ef);
                }
                return c < 6;
            });
        });
    }
    intervalEffect(u: unit, x: number, y: number) {
        DestroyEffect(AddSpecialEffect('Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl', x, y));
        let lv = this.getAbilityLevel(u);
        let dmg = 40 * lv + UnitCommon.取固定攻击(u) * (0.6 + 0.25 * lv);
        let es = SelectUtil.getEnemyUnitsInRange(u, 225, x, y);
        for (let e of es) {
            DamageSystemInstance.applyLightDamage(e, u, dmg, this.id);
            // BuffUtil.addBuff(e, this.buffType.id, u);
            BuffCommon.addBuff({ target: e, caster: u, buffTypeId: this.buffType.id, ablityId: this.id });
        }
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
